{include file="public/header" /}
<span class="layui-breadcrumb">
  <a href="javascript:;">品牌</a>
  <a><cite>列表</cite></a>
</span>
<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <div style="color:#FF5722">网站品牌设置,名称必填,图片以及链接选填,默认不在首页展示</div>
       
   
        <div class="layui-form">

          <div class="layui-form-item" style='margin-top:20px'>
            <div class="layui-input-inline">
             <button class="layui-btn layui-btn-normal layui-btn-sm" onclick="insert_edit('添加','tj')">添加</button>
            </div>

            <label class="layui-form-label">首页展示</label>
            <div class="layui-input-inline">
              <select name="isindex" id='isindex'>
                <option value=""></option>
                <option value="1" {eq name="$data_list.isindex" value="1"}selected{/eq}>展示</option>
                <option value="2" {eq name="$data_list.isindex" value="2"}selected{/eq}>不展示</option>
              </select>
            </div>

            <div class="layui-inline">
              <div class="layui-input-inline">
                <input type="text" name='brand_name' class="layui-input" placeholder="请输入品牌名称" value="{$data_list['brand_name']}">
              </div>
            </div>
          
            <div class="layui-inline">
              <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="sear()">查询</button>
              <a href="{:url('Brand/index')}?nav=brand-brandlist" class="layui-btn layui-btn-sm layui-btn-danger">清空</a>
            </div>
          </div>

          <table class="layui-table" id="script_table">
            <thead>
              <tr>
                <th>品牌名称</th>
                <th>图片</th>
                <th>链接</th>
                <th>首页展示</th>
                <th>创建时间</th>
                <th>状态</th>
                <th>操作</th>
              </tr> 
            </thead>
            <tbody>
              {volist name="data_list['list']" id="data"}
               <tr>
                <td>{$data.bname}</td>
                <td><img src="{$data.img}" style='width:100px;cursor:pointer;min-width:100px' onclick="show('{$data.img}')"></td>
                <td style='width:200px'><a href="{$data.linkurl}" style='color:#01AAED' title='打开' target='_blank'>{$data.linkurl}</a></td>
                <td>{eq name="$data.isindex" value="1"}展示{else/}不展示{/eq}</td>
                <td>{$data.create_time}</td>
                <td>{eq name="$data.status" value="1"}正常{else/}已删除{/eq}</td>
                <td>
                  {eq name="$data.status" value="1"}
                   <button type="button" class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$data.id})">删除</button>
                   <button type="button" class="layui-btn layui-btn-xs" onclick="insert_edit('编辑','{$data.id}','{$data.bname}','{$data.linkurl}','{$data.img}','{$data.isindex}')">编辑</button>
                  {/eq}
                </td>
              </tr>
              {/volist}
              
            </tbody>
          </table>
           {$data_list['list']|raw}
        </div>

      </div>  
    </div>
</div>

{include file="/public/footer" /}

<script>
  /*图片视频放大*/
  function show(url){
      layer.open({
        type: 2,
        title: false,
        area: ['60%', '50%'],
        shade: 0.8,
        closeBtn: 0,
        fixed: false,
        shadeClose: true,
        content: url
      });
  } 

  function del(id){
    layer.confirm('你确定要删除吗', {
      btn: ['确定','取消'] //按钮
    }, function(){
      layer.load();
      $.post("{:url('Brand/del')}",{id:id},function(res){
          if(res.status=='0'){
              layer.closeAll('loading');
              layer.msg(res.msg);
          }
          if(res.status=='1'){
              layer.msg(
              res.msg,{icon: 1,time: 600},
              function(){
                layer.closeAll('loading');
                location.href=location.href;
              });
          }
      })
    });
  }

 /*添加 或 修改 找change.html*/
 function insert_edit(type,id,bname,linkurl,img,isindex){
    layer.open({
      type: 2,
      title:type,
      area: ['600px', '50%'],
      maxmin: true,
      content: 'change.html',
      btn: ['提交'],
      yes: function (index,layero) {
          do_insert_edit(index,layero,id);//执行 
      },
      success: function(layero, index){
          var body = layer.getChildFrame('body', index);//子页面dom
           /*获取子页面输入内容*/
          if(id!='tj'){
              body.find("input[name='bname']").val(bname);
              body.find("input[name='linkurl']").val(linkurl);
              body.find("#show_img").attr('src',img);
              body.find("input[name='newname']").val(img);
              body.find("input[name='isindex']").each(function () {   
                if($(this).val()==isindex){
                  $(this).attr("checked", "checked");
                }else{
                  $(this).removeAttr("checked");
                }
              }) 
          }  
      }
    }); 
 }
 
/*执行添加或修改*/
 function do_insert_edit(index,layero,id){
      layer.load();
      var body = layer.getChildFrame('body', index);//子页面dom
      /*获取子页面输入内容*/
      var bname=$.trim(body.find("input[name='bname']").val());
      var linkurl=$.trim(body.find("input[name='linkurl']").val());
      var isindex=$.trim(body.find("input[name='isindex']:checked").val());
      var newname=$.trim(body.find("input[name='newname']").val());
      if(bname==''){
          layer.closeAll('loading');
          layer.msg('请填写名称');
          return false;
      }
      if(id=='tj'){
        var url="{:url('Brand/change')}";
      }else{
        var url="{:url('Brand/change')}"+"?id="+id;
      }
      $.post(url,{bname:bname,linkurl:linkurl,isindex:isindex,newname:newname},function(res){
          if(res.status=='0'){
              layer.closeAll('loading');
              layer.msg(res.msg);
          }
          if(res.status=='1'){
              layer.msg(
              res.msg,{time: 1500 },
              function(){
                layer.closeAll();
                location.href=location.href;
              });
          }
      }) 
 }

 /*查询*/
  function sear(){
    var brand_name=$.trim($("input[name='brand_name']").val());
    var isindex=$.trim($('#isindex option:selected').val());

    if(brand_name=='' && isindex==''){
        layer.msg('请输入查询条件');
        return false;
    }

    window.location.href="{:url('Brand/index')}"+"?nav=brand-brandlist&brand_name="+brand_name+"&isindex="+isindex;  
  }
</script>
